package day01;

/**
 * 位运算
 * & | ^ ~ << >> >>> 与 或  异或  取反  左移  右移  无符号右移
 * <<  1 左移 右边边用0来补
 * >>  1 右移 左边用符号位来补
 * >>> 1 右移 左边边用0来补
 */
public class Code1_printB {
    /**
     * 打印一个整数的二进制
     * @param num
     */
    public static void print(int  num){
        for (int i = 31; i >= 0; i--){
            System.out.print( (num & (1 << i)) ==0 ? "0":"1" );
        }
        System.out.println();
    }
    public static void main(String[] args) {
        int a = 5;
        int b = 6;
        print(a);
        System.out.println(a & b);
        System.out.println(a | b);
        System.out.println(a ^ b);
        System.out.println(~a);
        System.out.println(a << 2);
        System.out.println(a >> 2);
        System.out.println(a >>> 2);

        //取反
        int c = 10;
        System.out.println(-c);
        System.out.println(~c+1);
        //例外：最小数取反为该数
        int d = Integer.MIN_VALUE;
        System.out.println(-d);
        System.out.println(~d+1);
    }
}
